<template>
  <view class="start">
    <view class="input-view xs">姓氏:
        <input v-model="xs" />
    </view>
    <view class="input-view mz">
        名字:
        <input v-model="mz" />
    </view>
    <view class="mr-commit" @click="commit" :class="sizeStatus ? 'mr-commit-big' : 'mr-commit-small'"></view> 
    <LandscapeModel v-model:show="show" :sonFun="sonFun"/>
  </view>
</template>

<script setup lang="ts">
import LandscapeModel from "@/components/Landscape/LandscapeModel.vue";
import { EnumStatus } from "@/utils/constants";
import { xingmingDafen } from "@/utils/ab";
import dyUserPlayingService from "@/api/dyUserPlayingService";

const sizeStatus = ref(false)
const show = ref(false)
const xs = ref()
const mz = ref()
const emit = defineEmits(['update:defStatus','update:content'])



const sonFun = async()=>{
    const data = await xingmingDafen(xs.value,mz.value)
    emit('update:defStatus',EnumStatus.RESULT)
    emit('update:content',data)
}

const startTimer = () => {
    setInterval(() => {
        sizeStatus.value =  !sizeStatus.value
    }, 1000); // 每秒执行一次
  };

  const commit = async ()=>{

    if(!xs.value || !mz.value){
      uni.showToast({
        title:'请输入姓名',
        icon:'none'
    })
      return
    }

    await w(xs.value);
    await w(mz.value);
    if(await w(xs.value) || await w(mz.value)){
      return
    }
    uni.showLoading({
        title: "加载中",
        icon: "none",
    });
    uni.hideLoading()
    show.value = true
}

const w = async(str:string)=>{
  const {result}  = await dyUserPlayingService.sensitiveWord({word:str})
    if(result){
        uni.hideLoading()
        uni.showToast({
            title: '存在敏感词,请重新填写',
            duration: 2000,
            icon:"none"
        });
        return true
    }
    return false
}

onMounted(()=>{
      startTimer()
  })
</script>

<style lang="scss" scoped>
.start{
    .input-view {
      width: 60%;
      height: 80rpx;
      left: 20%;
      z-index: 102;
      position: absolute;
      background-image: url("http://img-miniprogram-o.doutuimao.net/miniadmin/programconfig/xcximg/20230726/21e173b2f16081e2e7bec63bdfb03800.png");
      background-size: 100% 100%;
      display: flex;
      align-items: center;
      padding-left: 8rpx;
      input{
        height: 100%;
        width: 70%;
      }
    }
    .xs{
      top: 65%;
    }
    .mz{
      top: 71%;
    }
    .mr-commit{
      z-index: 102;
      position: absolute;
      top: 86%;
      width: 60%;
      height: 100rpx;
      left: 20%;
      background-size: 100% 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      color: white;
      background-image: url("http://img-miniprogram-o.doutuimao.net/miniadmin/programconfig/xcximg/20230726/fd670e9b0aea978f337551bec1297ea7.png");
  }
  .mr-commit-big{
      width: 62%;
      height: 105rpx;
      left: 19%;
      transition: all 1s;
  }
  .mr-commit-small{
      width: 60%;
      height: 100rpx;
      left: 20%;
      transition: all 1s;
  }
}

</style>
